//截取位数
export const TimeDigit = (value, n, m) => {
	if (!value) return;
	return value.substring(n, m);
}

//取N位小数
export const Decimal = (value, n) => {
	if (!value) return;
	var m = Math.pow(10, n);
	if (value.toString().indexOf('-') != -1) {
		return Math.ceil(value * m) / m;
	} else {
		return Math.floor(value * m) / m;
	}
}

//过滤手机号码
export const MobileFilter = (value) => {
	return value.substr(0, 3) + '****' + value.substr(7, 4);
}

//过滤手机号码
// export const tradeNumFilter = (value) => {
// 	if(value.indexOf('%') != -1){
// 		//this.num = value
// 		parseInt(value)
// 	} 
// 	return value + '%'
// }

//将数值转化为亿并保留两位小数
export const numberFormat = (value, rate) => {
	let rates = rate || 7;
	let values = comm.accMul(value || 0, rates)
	let param = {};
	let k = 10000,
		i;
	if (values < k) {
		param.values = values
	} else {
		i = Math.floor(Math.log(values) / Math.log(k));
		if (i > 2) i = 2;
		param.values = ((values / Math.pow(k, i))).toFixed(2);
	}
	return Number(param.values);
}

//将数值转化为亿
export const numberFormatCompany = (value, rate) => {
	let rates = rate || 7;
	let values = comm.accMul(value || 0, rates)
	let param = {};
	let k = 10000,
		sizes = ['', '万', '亿'],
		i;
	if (values < k) {
		param.unit = ''
	} else {
		i = Math.floor(Math.log(values) / Math.log(k));
		if (i > 2) i = 2;
		param.unit = sizes[i];
	}
	return param.unit;
}

//时间戳转成时间
// export const timer = (value) => {
//   let valueLength = value.toString().length == 13 ? 1 : 1000;
//   let date = new Date(value * valueLength);
//   //时间戳为10位需*1000，时间戳为13位的话不需乘1000
//   let y = date.getFullYear();
//   let MM = date.getMonth() + 1;
//   MM = MM < 10 ? ('0' + MM) : MM;//月补0
//   let d = date.getDate();
//   d = d < 10 ? ('0' + d) : d;//天补0
//   let h = date.getHours();
//   h = h < 10 ? ('0' + h) : h;//小时补0
//   let m = date.getMinutes();
//   m = m < 10 ? ('0' + m) : m;//分钟补0
//   let s = date.getSeconds();
//   s = s < 10 ? ('0' + s) : s;//秒补0
//   return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
// }

//时间戳转成时间 'yyyy-MM-dd hh:mm'
export const timer = (value, fmt) => {
	if (!value) return;
	let newTime = new Date(value)
	if (/(y+)/.test(fmt)) {
		fmt = fmt.replace(RegExp.$1, (newTime.getFullYear() + '').substr(4 - RegExp.$1.length));
	}
	let o = {
		'M+': newTime.getMonth() + 1,
		'd+': newTime.getDate(),
		'h+': newTime.getHours(),
		'm+': newTime.getMinutes(),
		's+': newTime.getSeconds()
	};

	function padLeftZero(str) {
		return ('00' + str).substr(str.length);
	}

	// 遍历这个对象
	for (let k in o) {
		if (new RegExp(`(${k})`).test(fmt)) {
			// console.log(`${k}`)
			let str = o[k] + '';
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str));
		}
	}
	return fmt;
}

//业务类型
export const filType = (value, type) => {
	let name = ''
	let data = uni.getStorageSync('dataDictionary') || []
	let data2 = data.filter((item)=>{
		return item.dicCode == type
	})
	
	data2.length > 0 && data2.forEach(item=>{
		if(item.key == value) name = item.remark
	})
	return name
}

//过滤空值
export const filNull = (value) => {
	if (value === 0) return 0;
	if (!value) return "--";
	return value;
}